package jsyf.oa.web.system;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.system.UserAchievementsFacade;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by 92852 on 2018/8/2.
 */
@Api(value = "接口", description = "接口")
@Controller
@RequestMapping("/userAchievements")
public class UserAchievementsController {
    @Resource
    private UserAchievementsFacade userAchievementsFacade;

    @ResponseBody
    @RequestMapping(value = "/save.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "保存/修改",
            notes = "保存/修改",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "BigAchievementsEntity:''", dataType = "String", paramType = "body")
    public void save(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        String records = userAchievementsFacade.save(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(records));
    }

    @ResponseBody
    @RequestMapping(value = "/delById.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "逻辑删除",
            notes = "逻辑删除",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "id:''", dataType = "String", paramType = "body")
    public void delById(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = userAchievementsFacade.delById(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(records));
    }

    @ResponseBody
    @RequestMapping(value = "/removeById.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "物理删除",
            notes = "物理删除",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "id:''", dataType = "String", paramType = "body")
    public void removeById(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = userAchievementsFacade.removeById(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(records));
    }

    @ResponseBody
    @RequestMapping(value = "/getListByUserId.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询列表",
            notes = "查询列表",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "userId:''", dataType = "String", paramType = "body")
    public void getListByUserId(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = userAchievementsFacade.getListByUserId(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(records));
    }

    @ResponseBody
    @RequestMapping(value = "/getDetailById.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询详情",
            notes = "查询详情",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "id:''", dataType = "String", paramType = "body")
    public void getDetailById(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = userAchievementsFacade.getDetailById(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(records));
    }

    /**
     * 获取所有公司
     */
    @ApiOperation(
            value = "获取团队组建考核",
            notes = "获取团队组建考核",
            httpMethod = "POST",
            response = ResponseUtils.class,
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jsonData", value = "", dataType = "参数类型（string）", paramType = "参数类型（json）")
    })
    @ResponseBody
    @RequestMapping(value = "/getAchievementByCompany.json", method = RequestMethod.POST)
    public void getAchievementByCompany(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        List<JSONObject> records = this.userAchievementsFacade.getAchievementByCompany(jsonData);
        if (records != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }


}
